<?php
$smarty->configLoad($lang . '/creport.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$breadcrumb = $language['creport'];
$new_reports = '';
$old_value = '';
$value = ''; 

/* New Reports Count*/
$sql = 'SELECT * FROM '.DB_CMS.'.module_creport WHERE DATE_SUB(NOW(), INTERVAL 7 DAY) < timestamp';
$dbh = $connection->prepare($sql);
$dbh->execute();
$new_reports = $dbh->rowCount();
$smarty->assign('new_reports', $new_reports);

/* New Reports Foreach*/
$sql = 'SELECT * FROM '.DB_CMS.'.module_creport WHERE  DATE_SUB(NOW(), INTERVAL 7 DAY) < timestamp';
$dbh = $connection->prepare($sql);
$dbh->execute();
$user = new user;
$sql = 'SELECT SUM(stars) as stars FROM '.DB_CMS.'.module_creport WHERE userID = :userID';
foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':userID', $row['userID']);
	$dbh->execute();
	$stm = $dbh->fetch();

	$row['allstars'] =  $stm['stars'];
	$row['img'] = $user->stars($row['stars']);
	$row['username'] = $user->getName($row['userID']);
	$value[] = $row;
}

$smarty->assign('new_value', $value);
/* Old Reports Count*/
$sql = 'SELECT * FROM '.DB_CMS.'.module_creport WHERE DATE_SUB(NOW(), INTERVAL 7 DAY) > timestamp';
$dbh = $connection->prepare($sql);
$dbh->execute();
$new_reports = $dbh->rowCount();
$smarty->assign('old_reports', $new_reports);

/* Old Reports Foreach*/
$sql = 'SELECT * FROM '.DB_CMS.'.module_creport WHERE  DATE_SUB(NOW(), INTERVAL 7 DAY) > timestamp';
$dbh = $connection->prepare($sql);
$dbh->execute();
$user = new user;
$sql = 'SELECT SUM(stars) as stars FROM '.DB_CMS.'.module_creport WHERE userID = :userID';

foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':userID', $row['userID']);
	$dbh->execute();
	$stm = $dbh->fetch();

	$row['allstars'] =  $stm['stars'];
	$row['img'] = $user->stars($row['stars']);
	$row['username'] = $user->getName($row['userID']);
	$old_value[] = $row;
}


$smarty->assign('old_value', $old_value);
$template = 'creport/index.tpl';
?>
 